
package ija.model.history;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Radek Necas, xnecas18
 */
public class History implements Iterable<HistoryMove> {
    
    protected ArrayList<HistoryMove> moves;
    
    public History() {
        moves = new ArrayList<>();
    }
    
    public History(List moves) {
        this.moves = new ArrayList<>(moves);
    }
    
    public HistoryMove getMove(int position) {
        if(position > 0 && position < moves.size()) {
            return moves.get(position);
        }
        
        return null;
    }
    
    public boolean addMove(HistoryMove m) {
        if(m.isComplete()) {
            moves.add(m);
            return true;
        }
        
        return false;
    }

    @Override
    public Iterator<HistoryMove> iterator() {
        return moves.iterator();
    }
    
    public void print() {
        Iterator<HistoryMove> it = iterator();
        for(HistoryMove hm: this) {
            System.out.println(hm.toString());
        }
    }
}
